<template>
    <div class="title">
        <div class="text">
            <span class="dec" />
            <span class="title-name">
                {{ title }}
                <slot name="other" />
            </span>
            <div v-if="collapse" class="collapse" @click="handleCollapse">
                <i class="el-icon-d-arrow-right" :class="{'arrow-top': status}" />
            </div>
            <slot name="button" />
        </div>
        <span v-if="required" class="tips">为必填项</span>
    </div>
</template>

<script>
export default {
    name: 'TitleTips',
    props: {
        title: {
            type: String,
            default: ''
        },
        required: {
            type: Boolean,
            default: false
        },
        collapse: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            status: false
        }
    },
    methods: {
        handleCollapse() {
            this.status = !this.status
            this.$emit('change', this.status)
        }
    }
}
</script>

<style lang="scss" scoped>
.collapse {
    font-weight: bold;
    padding: 0 24px;
    cursor: pointer;
    .el-icon-d-arrow-right {
        transition: 0.3s;
        transform: rotate(90deg)
    }
    .arrow-top {
        transform: rotate(-90deg)
    }
}
.title {
    width: 100%;
    height: 20px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #171725;
    position: relative;
    .text {
        display: flex;
        align-items: center;
        .dec {
            display: inline-block;
            width: 2px;
            height: 1em;
            background: #0062FF;
            margin-right: 8px;
        }
        .title-name {
            font-weight: bold;
        }
        .button {
            margin-left: 24px;
        }
    }
    .tips:before {
        content: '*';
        color: #E50834;
        margin-right: 4px;
    }
}
</style>
